﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Security.Principal;
using System.Xml.Linq;

namespace COM.Data
{
    /// <summary>
    /// 通用用户角色定义,没有扩展鉴权参数
    /// </summary>
    public abstract class PermissionRole
    {
        public virtual bool IsAuthenticated
        {
            get
            {
                return true;
            }
        }

        public abstract string EnumRoleName
        {
            get;
        }

        public virtual XElement RoleDataXml
        {
            get
            {
                return new XElement("r", this.EnumRoleName);
            }
        }

        public virtual void ParseXml(XElement x)
        {
        }
    }

    /// <summary>
    /// 所有已验证的,未验证的角色,匿名用户也有此角色
    /// 但data service必须是已验证的角色才能显示数据
    /// </summary>
    public class AnyPermissionRole : PermissionRole
    {
        private static AnyPermissionRole instance;
        public static AnyPermissionRole Instance
        {
            get
            {
                return instance ?? (instance = new AnyPermissionRole());
            }
        }

        public override string EnumRoleName
        {
            get
            {
                return "_Any";
            }
        }

        public override bool IsAuthenticated
        {
            get
            {
                return false;
            }
        }
    }

}


